package util;

public class FenYe {
	// oracle分页
	public static String getPage(String sql, Page page) {
		int start = page.getStartNum();
		int size = page.getPageSize();
		if (start < 0) {
			throw new IllegalArgumentException("start不能小于0");
		}
		if (size < 0) {
			throw new IllegalArgumentException("size大小不能小于0");
		}
		if (start == 0) {
			start = 1;
		}
		if (size == 0) {
			return sql;
		}
		StringBuffer sb = new StringBuffer();
		sb.append("select * from (select nummax.*, rownum as row_id from (");
		sb.append(sql);
		sb.append(") nummax where rownum<").append(size + start).append(
				")where row_id >=");
		sb.append(start);
		return sb.toString();
	}

	public static String getCount(String sql) {
		StringBuffer sb = new StringBuffer();
		sb.append("select count(*) as count from (");
		sb.append(sql);
		sb.append(")");
		return sb.toString();
	}
}
